package broadcaster;

import java.util.ArrayList;
import java.util.List;

import listener.Listener;

public abstract class Broadcaster {
  
  private List<Listener> listeners_;
  
  public Broadcaster() {
    listeners_ = new ArrayList<Listener>();
  }
  
  public void addListener(Listener new_listener) {
    assert (new_listener != null);
    if (listeners_.contains(new_listener)) {
      // TODO?
    } else {
      listeners_.add(new_listener);
    }
  }
  
  public void removeListener(Listener old_listener) {
    assert (old_listener != null);
    if (listeners_.contains(old_listener)) {
      listeners_.remove(old_listener);
    }
  }
  
  public void fire() {
    for (Listener listener : listeners_) {
      listener.respond(this);
    }
  }
  
}
